package com.lbs.jiepiaisi.biz;

import android.content.Intent;
import android.util.Log;

import com.lbs.jiepiaisi.bean.PhotoImgBean;
import com.lbs.jiepiaisi.manager.App;
import com.lbs.jiepiaisi.parser.PhotoImageParser;
import com.lbs.jiepiaisi.utils.Constant;
import com.lbs.jiepiaisi.utils.HttpUtil;
import com.lbs.jiepiaisi.utils.UrlUtil;

import okhttp3.FormBody;
import okhttp3.Response;

/**
 *
 * 时间：2018/1/15 13:48
 * 作用：查询图片
 */

public class PhotoLoadBiz {
    public void findImageBiz(String eqId) {
        //获得sp存储的部门id
        FormBody formBody = new FormBody
                .Builder()
                .add("eqId",eqId)//设置参数名称和参数值/*String.valueOf(deptId)*/
                .build();
        HttpUtil.getHttpUtil().post(UrlUtil.IMAGE_FIND_IMAGE, formBody, new HttpUtil.Listener() {
            @Override
            public void success(Response response) {

                PhotoImgBean photoImgBean = new PhotoImgBean();
                try{
                    //返回结果
                    String jsonString = response.body().string();
                    Log.e("findImageBiz", jsonString);
                    photoImgBean = PhotoImageParser.parser(jsonString);
                }catch (Exception e){
//                    photoImgBean.setStatus(Constant.STATUS_NETWORK_ERROR);
                    e.printStackTrace();
                }finally {
                    Intent intent = new Intent(Constant.FIND_UPLOAD_PICTURE);
                    intent.putExtra(Constant.KEY_DATA, photoImgBean);
                    App.instance.sendBroadcast(intent);
                }
            }
            @Override
            public void failed() {
                PhotoImgBean photoImgBean =new PhotoImgBean();
//                photoImgBean.setStatus(Constant.STATUS_NO_NET);
                Intent intent = new Intent(Constant.FIND_UPLOAD_PICTURE);
                intent.putExtra(Constant.KEY_DATA, photoImgBean);
                App.instance.sendBroadcast(intent);
            }
            @Override
            public void noNetwork() {
                PhotoImgBean photoImgBean =new PhotoImgBean();
//                photoImgBean.setStatus(Constant.STATUS_NETWORK_ERROR);
                Intent intent = new Intent(Constant.FIND_UPLOAD_PICTURE);
                intent.putExtra(Constant.KEY_DATA, photoImgBean);
                App.instance.sendBroadcast(intent);
            }
        });
    }


}
